<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class gopy extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model('model_gopy');
		date_default_timezone_set("Asia/Ho_Chi_Minh");
	}

	public function index(){
		$chucvu = $this->session->userdata('prie_username');
		if($chucvu)
		{
			$data['chude'] = $this->model_gopy->layChuDe($chucvu);

			$this->load->view("view_header");
			$this->load->view("view_login");
			$this->load->view("view_body_gopy",$data);
			$this->load->view("view_footer");
		}
		else
		{
			redirect(base_url() . "login");
		}
	}

	public function shoutbox(){
		$shoutbox = $this->model_gopy->layShoutBox();
		foreach ($shoutbox as $value) {
			echo '<span style="color: #c0a16b;font-weight: bold;">',$value->ten,': </span>',
			$value->noidung,'<div class="shoutbox_thoigian">',$value->thoigiandang,'</div><div class="line_chat"></div>';
		}
	}

	public function luushoutbox(){
		$data = array
		(
			'ten' => $this->session->userdata('prie_username'),
			'thoigiandang' => date("Y-m-d h-i-s"),
			'noidung' => $_POST['noidung'],
		);
		$this->model_gopy->luunoidungshoutbox($data);
	}

	public function chitietgopy(){
		$magopy = $_GET['magopy'];
		//lấy chủ đề và mã góp ý
		$chude = $this->model_gopy->layTieuDeGopY($magopy);
		$data['chude'] = $chude['0']->tieude;
		$data['magopy'] = $magopy;
		//lấy chi tiết góp ý
		$data['chitietgopy'] = $this->model_gopy->layChiTietGopY($magopy);
		
		$this->load->view("view_header");
		$this->load->view("view_login");
		$this->load->view("view_body_chitietgopy",$data);
		$this->load->view("view_footer");
	}

	public function luuguiykien(){
		$data = array
		(
			'magopy' => $_POST['magopy'],
			'ten' => $this->session->userdata('prie_username'),
			'anhdaidien' => 'images/avatar.jpg',
			'chucvu' => $this->session->userdata('prie_phanloai'),
			'thoigiantao' => date("Y-m-d h-i-s"),
			'noidung' => $_POST['traloi'],
		);
		$this->model_gopy->luutraloigopy($data);
	}

	public function taogopy(){
		$magopy = $this->model_gopy->laymagopycuoi();
		$data['magopy'] =  $magopy['0']->magopy + 1;

		$this->load->view("view_header");
		$this->load->view("view_login");
		$this->load->view("view_body_taogopy",$data);
		$this->load->view("view_footer");
	}

	public function luutaogopy(){
		$nguoixem;
		if($_POST['giaovien'] == '' && $_POST['phuhuynh'] == '') $nguoixem = 'tất cả';
			else 
			{
				$nguoixem .= $_POST['giaovien'];
				$nguoixem .= ',';
				$nguoixem .= $_POST['phuhuynh'];
			}
		$data = array
		(
			'magopy' => $_POST['magopyke'],
			'tieude' => $_POST['tieudegopy'],
			'taoluc' => date("Y-m-d h-i-s"),
			'binhluancuoi' => date("Y-m-d h-i-s"),
			'codinh' => 0,
			'nguoixem' => $nguoixem,
		);
		$this->model_gopy->luutaogopy($data);

		$data2 = array
		(
			'magopy' => $_POST['magopyke'],
			'ten' => $this->session->userdata('prie_username'),
			'anhdaidien' => 'images/avatar.jpg',
			'chucvu' => $this->session->userdata('prie_phanloai'),
			'thoigiantao' => date("Y-m-d h-i-s"),
			'noidung' => $_POST['noidunggopy'],
		);
		$this->model_gopy->luutraloigopy($data2);
	}

	public function timgopy(){
		$chudetim = $_POST['chudetim'];
		$chucvu = $this->session->userdata('prie_username');

		$data['chude'] = $this->model_gopy->timtheochude($chudetim, $chucvu);

		$this->load->view("view_header");
		$this->load->view("view_login");
		$this->load->view("view_body_gopy",$data);
		$this->load->view("view_footer");
	}

	public function test(){
		$magopy = $this->model_gopy->laymagopycuoi();
		echo $magopy['0']->magopy + 1;
	}
}